//
//  GetGoodsVieController.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/23.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class GetGoodsVieController: TableBaseViewController,GetGoodViewDelegate,TableDelegate {
    
    var v = GetGoodView()
    
    //导航栏设置还原
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //继承基础类的代理
        self.t_delegate = self
        
        //取消返回手势,防止用户不小心返回页面，输入的个人信息丢失
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
        
        self.navigationController?.navigationBar.isHidden = false
        UIApplication.shared.statusBarStyle = UIStatusBarStyle.default
        
        
        //若程序运行期间，收获地址的值发生改变，则优先从单例中取出改变的值进行显示
//        if GetGoodModel.shared.addDic != nil {
//            //收货人
//            GetGoodView.shared.tfName.text = GetGoodModel.shared.shrName
//            //手机号码
//            GetGoodView.shared.tfNum.text = GetGoodModel.shared.shrphone
//            //省份
//            GetGoodView.shared.tfProvince.text = GetGoodModel.shared.province
//            //城市
//            GetGoodView.shared.tfCity.text = GetGoodModel.shared.city
//            //地区
//            GetGoodView.shared.tfArea.text = GetGoodModel.shared.area
//            //详细地址
//            GetGoodView.shared.tfView.text = GetGoodModel.shared.street
//        } else {
//            return
//        }
        
        print(GetGoodModel.shared.shrphone)
        
        if GetGoodModel.shared.shrName != nil {
            GetGoodView.shared.tfName.text = GetGoodModel.shared.shrName
            
        }
        if GetGoodModel.shared.shrphone != nil {
            GetGoodView.shared.tfNum.text = GetGoodModel.shared.shrphone
            
        }
        if GetGoodModel.shared.province != nil {
            GetGoodView.shared.tfProvince.text = GetGoodModel.shared.province
            
        }
        if GetGoodModel.shared.city != nil {
            GetGoodView.shared.tfCity.text = GetGoodModel.shared.city
            
        }
        if GetGoodModel.shared.area != nil {
            GetGoodView.shared.tfArea.text = GetGoodModel.shared.area
            
        }
        if GetGoodModel.shared.area != nil {
            GetGoodView.shared.tfView.text = GetGoodModel.shared.street
        } else {}
    }
    
    //页面结束后，恢复左滑手势
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        self.view.endEditing(true)

        
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "我的收货地址"
        
        // Do any additional setup after loading the view.
        view.backgroundColor = UIColor.white
        setUI()
        
        setStyle()
    }
}


extension GetGoodsVieController {
    func setUI() -> Void {
        v.frame = view.bounds
        v.delegate = self
        view.addSubview(v)
    }
}


extension GetGoodsVieController {
    func setStyle() -> Void {

        tableView.separatorStyle = UITableViewCellSeparatorStyle.none

    }
}

// MARK:- 监听代理
extension GetGoodsVieController {
    func backToGood() {
        print("返回主页")
        self.navigationController!.popToRootViewController(animated: true)
    }
}


// MARK:- 实现基类的方法
extension GetGoodsVieController {
    func click() {
        
        let alert = UIAlertController.init(title: "提示", message: "您确定要放弃当前编辑的内容么?", preferredStyle: .alert)
        
        
        alert.addAction(UIAlertAction.init(title: "放弃编辑", style: .destructive, handler: { (nil) in
            //            self.navigationController!.popViewController(animated: true)
            // pop here
            if let navController = self.navigationController {
                navController.popViewController(animated: true)
            }
        }))
        
        alert.addAction(UIAlertAction.init(title: "留在此页", style: .default, handler: nil))
        
        self.present(alert, animated: true, completion: nil)
        
        
    }
}
